<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../fragments/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="decorator" content="default"/>
</head>
<body>
<div title="救援机构成员管理" style="padding:10px">
    <div id="tb" style="padding:3px">
        <span>成员名称:</span>
        <input class="easyui-searchbox" name="mem_name" data-options="prompt:'请输入成员姓名',searcher:doSearch" style="width:200px">
    </div>
    <table id="dg"  class="easyui-datagrid" style="height:400px"
           url="${ctx}/org_mem/list?orgId=${orgId}"
           toolbar="#toolbar" pagination="true"
           rownumbers="true" fitColumns="true" singleSelect="true" data-options="queryParams: {
                'pageSize' : function(){
                    return $('#dg').datagrid('getPager').pagination('options').pageSize;
                },
                'pageNumber' : function(){
                    return $('#dg').datagrid('getPager').pagination('options').pageNumber;
                }
            }">
        <thead>
        <tr>
            <th field="name" width="50">姓名</th>
            <th field="contact" width="50">联系方式</th>
            <th field="org_name" width="50">所属机构</th>
            <th field="title" width="50">职务</th>
        </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newMember()">新建</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editMem()">编辑</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyMem()">删除</a>
    </div>

    <div id="dlg" class="easyui-dialog" style="width:400px"
         closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" action="" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">救援机构成员信息</div>
            <input type="hidden" name="user_id" id="user_id">
            <input type="hidden" name="mem_id" >
            <input type="hidden" name="om_id" >
            <div style="margin-bottom:10px">
                <input name="is_sys_user" id="sysMem" type="radio" onclick="clickSysMem();" value="0">系统用户
                <input name="is_sys_user" id="noSysMem" type="radio"  onclick="clickNoSysMem();" value="1">非系统用户
            </div>
            <div id="sysMemName" style="margin-bottom:10px">
                <select id="sysUser_select"  class="easyui-combobox" label="选择用户:"  style="width:90%">
                    <c:forEach items="${sysUser}" var="user" >
                        <option  value="${user.ID}">${user.LOGIN_NAME}</option>
                    </c:forEach>
                </select>
            </div>
            <div  style="margin-bottom:10px">
                <input name="name"  id="name" class="easyui-textbox" required="true" label="姓名:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="contact" id="contact" class="easyui-textbox" required="true" label="应急联系方式:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <select name="org_id" id="org_id" class="easyui-combobox" label="所属机构:" style="width:90%">
                    <c:forEach items="${aidOrg}" var="org">
                        <option value="${org.id}">${org.name}</option>
                    </c:forEach>
                </select>
            </div>
            <div style="margin-bottom:10px">
                <input name="title"  class="easyui-textbox" required="true" label="机构内职务:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="title"  class="easyui-textbox" required="true" label="所在单位:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="title"  class="easyui-textbox" required="true" label="单位内职务:" style="width:100%">
            </div>
        </form>
    </div>

    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveMem()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
        var url;
        function newMember(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','创建');
            $('#fm').form('clear');
            document.getElementById("sysMem").checked = true;//设置默认选中
            <c:if test="${orgId!=null}">
            $('#org_id').combobox('setValue',${orgId});
            </c:if>
        }
        function editMem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑');
                if(row.is_sys_user==0){
                    document.getElementById("sysMem").checked = true;//设置默认选中
                    document.getElementById("sysMem").disabled = true;//设置不可更改
                }else if(row.is_sys_user==1){
                    document.getElementById("noSysMem").checked = true;//设置默认选中
                    document.getElementById("noSysMem").disabled = true;//设置不可更改
                }
                $('#fm').form('load',row);
            }
        }
        function saveMem(){
            $('#fm').form('submit',{
                url:"${pageContext.request.contextPath}/org_mem/edit",
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.status==1){
                        $.messager.show({
                            title: 'Error',
                            msg: result.msg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        function destroyMem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('确认','确定删除吗？',function(r){
                    if (r){
                        $.post('${ctx}/org_mem/delete',{om_id:row.om_id,mem_id:row.mem_id},function(result){
                            if (result.status==0){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: '错误',
                                    msg: result.msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        function doSearch(){
            $('#dg').datagrid('load',{
                name: $('input[name=mem_name]').val()
            });
        }
        $(function(){
            $("#p_org").hide();

        })
        function clickNoSysMem(){
            $("#sysMemName").hide();
        }
        function clickSysMem(){
            $("#sysMemName").show();
        }

        $("#sysUser_select").combobox({
            onChange: function (newValue, oldValue) {
                setText(newValue);
            }
        })

        var array = eval('${sysUser_Json}');
        function setText(userId){
            for(var item in array){
                if(userId==array[item].ID){
                    $("#user_id").val(array[item].ID);
                    $("#name").textbox("setValue",array[item].NAME);
                    $("#contact").textbox("setValue",array[item].MOBILE);
                }
            }
        }
    </script>
</div>
</body>
</html>
